package com.youtills.core.auth.db.dao;


import com.youtills.core.auth.IAuth;
import com.youtills.core.auth.Resource;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: ravi
 * Date: 8/14/12
 * Time: 10:54 AM
 * To change this template use File | Settings | File Templates.
 */
public class Auth implements IAuth {

    private int authId;
    private String authKey;
    private AuthUser authUser;
    private Date createdDate;
    private Date modifiedDate;
    private long lastValidatedTime;

    public int getAuthId() {
        return authId;
    }

    public void setAuthId(int authId) {
        this.authId = authId;
    }

    public String getAuthKey() {
        return authKey;
    }

    public void setAuthKey(String authKey) {
        this.authKey = authKey;
    }

    public AuthUser getAuthUser() {
        return authUser;
    }

    public void setAuthUser(AuthUser authUser) {
        this.authUser = authUser;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    long getLastValidatedTime() {
        if(lastValidatedTime == 0){
            if(modifiedDate != null){
                lastValidatedTime = modifiedDate.getTime();
            } else if(createdDate != null){
                lastValidatedTime = createdDate.getTime();
            }
        }
        return lastValidatedTime;
    }

    void setLastValidatedTime(long lastValidatedTime) {
        this.lastValidatedTime = lastValidatedTime;
    }

    public Resource getAuthResource() {
        return getAuthUser();
    }
}
